import { Entity, PrimaryGeneratedColumn, CreateDateColumn, Column, ManyToOne, JoinColumn, OneToMany, } from 'typeorm';
import { Exclude } from 'class-transformer'
import { User } from './user.entity';
import { ArticleCover } from './articleCover.entity'
import { ArticleMoment } from './articleMoment.entity'
import { ArticleLike } from './articleLike.entity'
import { ArticleCollect } from './articleCollect.entity'

@Entity()
export class Article {
    @PrimaryGeneratedColumn('uuid')
    article_id: string;

    @Column()
    title: string;

    @Column('text')
    content: string;

    @Column()
    status: number; // 0 审核中  1 审核通过  2 审核不通过 3 删除 4 尽自己可见

    @Column({ nullable: true })
    topic_id: string | null;

    @Column({ nullable: true })
    address: string | null;

    @Column({ default: false, select: false })
    isDelete: boolean;

    @CreateDateColumn({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP(6)', select: true })
    createdAt: Date;

    @CreateDateColumn({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP(6)', select: false })
    updatedAt: Date;

    @OneToMany(() => ArticleCover, articleCover => articleCover.article)
    covers: ArticleCover[];

    @ManyToOne(() => User, user => user.articleUser)
    @JoinColumn({ name: 'author_id' })
    author: User;

    @OneToMany(() => ArticleMoment, articleMoment => articleMoment.article)
    @JoinColumn({ name: 'moment_id' })
    comments: ArticleMoment[]

    @OneToMany(() => ArticleLike, articlelike => articlelike.article)
    likes: ArticleLike[]

    @OneToMany(() => ArticleCollect, articleCollect => articleCollect.article)
    collects: ArticleCollect[]

    @Exclude()
    commentCount?: number | undefined

    @Exclude()
    likeCount?: number | undefined

    @Exclude()
    collectCount?: number | undefined

    @Exclude()
    isLike?: boolean | undefined

    @Exclude()
    isCollect?: boolean | undefined





}